﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Palsta.Core.data
{
    class BooleanField : Field
    {
        private bool value;

        public BooleanField(bool v)
        {
            this.value = v;
        }
        override public String GetStringValue()
        {
            if (value)
            {
                return "true";
            }
            else
            {
                return "false";
            }
        }

        override public Boolean SetValue(String v)
        {
            if (v.Equals("1") || v.ToLower().Equals("true"))
            {
                this.value = true;
            }
            else
            {
                this.value = false;
            }
            return true;
            
        }

        override public FieldType GetFieldType()
        {
            return FieldType.Boolean;
        }

        override public Boolean Equels(Field f)
        {
            if (f.GetFieldType() == FieldType.String)
            {
                bool b = f.GetStringValue().ToLower().Equals("true");
                return this.value == b;
            }
            if (f.GetFieldType() != FieldType.Boolean)
            {
                return false;
            }
            return this.value == ((BooleanField)f).value;
        }

        override public Boolean NotEquels(Field f)
        {
            return !this.Equals(f);
        }

        public bool GetBooleanValue()
        {
            return this.value;
        }

        public void SetBooleanValue(bool v)
        {
            this.value = v;
        }
    }
}
